package com.learn.observer;

import com.learn.observer.generic.GApp;
import com.learn.observer.generic.GTv;
import com.learn.observer.generic.GWeather;
import com.learn.observer.normal.App;
import com.learn.observer.normal.Tv;
import com.learn.observer.normal.Weather;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>项目名称: design-pattern </p>
 *
 * <p>文件名称: Application </p>
 *
 * <p>描述: TODO </p>
 */
@Slf4j
public class Application {

    public static void main(String[] args) {
        log.info("------------------normal-----------------------------");
        Weather weather = new Weather("上海徐汇");
        Weather weather2 = new Weather("上海浦东新区");

        App app1 = new App("天气app");
        App app2 = new App("墨墨app");

        Tv tv1 = new Tv("上海TV1");
        Tv tv2 = new Tv("上海TV2");

        weather.addObserver(app1);
        weather.addObserver(app2);
        weather.addObserver(tv1);
        weather.addObserver(tv2);

        weather.timePass();
        weather.timePass();


        weather2.addObserver(app1);
        weather2.addObserver(app2);
        weather2.addObserver(tv1);
        weather2.addObserver(tv2);

        weather2.timePass();
        weather2.timePass();

        log.info("------------------generic-----------------------------");

        GWeather gWeather = new GWeather("上海长宁");
        GWeather gWeather2 = new GWeather("上海闸北");

        GApp gApp1 = new GApp("天气app");
        GApp gApp2 = new GApp("墨墨app");
        GTv gTv1 = new GTv("上海TV1");
        GTv gTv2 = new GTv("上海TV2");

        gWeather.addObserver(gApp1);
        gWeather.addObserver(gApp2);
        gWeather.addObserver(gTv1);
        gWeather.addObserver(gTv2);

        gWeather.timePasses();
        gWeather.timePasses();

        gWeather2.addObserver(gApp1);
        gWeather2.addObserver(gApp2);
        gWeather2.addObserver(gTv1);
        gWeather2.addObserver(gTv2);

        gWeather2.timePasses();
        gWeather2.timePasses();
    }
}
